"""
---------------------------------------------------------------------
- File: init.py
- Date: 2025/11/14
- Author: yangzhide
- Email: xxzjyzd@126.com
- Description: 整理main中初始化代码,静态资源加载：
- 1. 全局异常
- 2. 路由
--3. 中间件
---------------------------------------------------------------------
"""
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

from app.api.v1.api import routeList
from app.core.exceptions import register_exception_handlers
from app.core.middleware import LogMiddleware


def init_app(app: FastAPI) -> None:
    # 注册全局异常处理
    register_exception_handlers(app)
    # 注册路由
    [app.include_router(router) for router in routeList]
    # 中间件 - 跨域
    app.add_middleware(
        CORSMiddleware,
        allow_origins=["*"],
        allow_credentials=True,
        allow_methods=["*"],
        allow_headers=["*"],
    )
    # 中间件 - 日志
    app.add_middleware(LogMiddleware)